home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / s-strops.adb < prev    next >
Text File  |  1996-01-30  |  3KB  |  71 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS                --
  4. --                                                                          --
  5. --                    S Y S T E M . S T R I N G _ O P S                     --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.4 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. package body System.String_Ops is
  27.  
  28.    ----------------
  29.    -- Str_Concat --
  30.    ----------------
  31.  
  32.    function Str_Concat (X, Y : String) return String is
  33.    begin
  34.       if X'Length <= 0 then
  35.          return Y;
  36.  
  37.       else
  38.          declare
  39.             L : constant Natural := X'Length + Y'Length;
  40.             R : String (X'First .. X'First + L - 1);
  41.  
  42.          begin
  43.             R (X'Range) := X;
  44.             R (X'First + X'Length .. R'Last) := Y;
  45.             return R;
  46.          end;
  47.       end if;
  48.    end Str_Concat;
  49.  
  50.    ---------------
  51.    -- Str_Equal --
  52.    ---------------
  53.  
  54.    function Str_Equal (A, B : String) return Boolean is
  55.    begin
  56.       if A'Length /= B'Length then
  57.          return False;
  58.  
  59.       else
  60.          for J in A'Range loop
  61.             if A (J) /= B (J + (B'First - A'First)) then
  62.                return False;
  63.             end if;
  64.          end loop;
  65.  
  66.          return True;
  67.       end if;
  68.    end Str_Equal;
  69.  
  70. end System.String_Ops;
  71.